#include <iostream>
#include <tuple>
#include <map>
#include <array>

struct Point
{
    double x{}, y{};
};

int main()
{
    // 1. std::pair
    auto p = std::make_pair(3, 4.5);
    auto [a, b] = p; // a=3, b=4.5
    std::cout << "pair: " << a << ", " << b << '\n';

    // 2. std::tuple
    auto t = std::make_tuple(1, 2.5, "hello");
    auto [i, f, s] = t; // 自动推导类型
    std::cout << "tuple: " << i << ", " << f << ", " << s << '\n';

    // 3. 数组
    std::array<int, 3> arr{7, 8, 9};
    auto [x, y, z] = arr; // x=7, y=8, z=9
    std::cout << "array: " << x << y << z << '\n';

    // 4. 自定义结构体
    Point pt{1.2, 3.4};
    auto [px, py] = pt; // px=1.2, py=3.4
    std::cout << "Point: " << px << ", " << py << '\n';

    // 5. 配合 map 遍历
    std::map<std::string, int> map{{"apple", 2}, {"banana", 5}};
    for (const auto &[key, val] : map)
        std::cout << key << " => " << val << '\n';
    return 0;
}